#include "util.h"

#include <fstream>
#include <iostream>
#include <sstream>
#include <list>
#include <ctime>

using namespace std;	
	
string readFile(const char *filename) {
	string fstr;

	ifstream stream(filename);

	char readBuffer[1000];
	int size;
	do {
		stream.read(readBuffer, sizeof(readBuffer));
		size=stream.gcount();
		fstr.append(readBuffer, size);
	} while(size > 0);

	return fstr;
}

long ms() {
	const long factor=1000/CLOCKS_PER_SEC;
	return clock()/factor;
}

void check(string errors) {
	if(errors.size())
		die(errors);
}

string getFps() {
	using namespace std;

	static list<long> timestamps;

	long now=ms();

	timestamps.push_back(now);

	while(now - timestamps.front() > 1000)
		timestamps.pop_front();

	stringstream ss;
	ss << timestamps.size();
	return ss.str();
}

SuperUseHandle::~SuperUseHandle() {}